//package com.cqc.config2;
//
//import com.baomidou.mybatisplus.annotation.DbType;
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import com.zaxxer.hikari.HikariDataSource;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//
///**
// * @author cui
// * @date 2025/7/5 20:25
// * @description  https://mp.weixin.qq.com/s/x9aAP1lCJNDNPKx9fUxVDA  DataSourceBuilder创建datasource
// **/
//@Configuration
//@MapperScan(basePackages = {"com.cqc.dao.db1"}, sqlSessionFactoryRef = "db1SqlSessionFactory")
//public class DB1Config {
//
//    @Primary
//    @Bean
//    @ConfigurationProperties(prefix = "spring.datasource.db1")
//    public DataSourceProperties db1DataSourceProperties() {
//        return new DataSourceProperties();
//    }
//
//    @Bean
//    @Primary
//    @ConfigurationProperties(prefix = "spring.datasource.db1.configuration")
//    public HikariDataSource db1HikariDataSource(@Qualifier("db1DataSourceProperties") DataSourceProperties db1DataSourceProperties) {
//        return db1DataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
//    }
//
//
//    @Bean
//    @Primary
//    public SqlSessionFactory db1SqlSessionFactory(@Qualifier("db1HikariDataSource") HikariDataSource db1HikariDataSource) throws Exception {
//        MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
//        factoryBean.setDataSource(db1HikariDataSource);
//        factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db1/*.xml"));
//        factoryBean.setPlugins(db1MybatisPlusInterceptor());
//        return factoryBean.getObject();
//    }
//
//    @Bean
//    @Primary
//    public MybatisPlusInterceptor db1MybatisPlusInterceptor() {
//        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        //分页
//        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//        return interceptor;
//    }
//
//    @Bean
//    @Primary
//    public SqlSessionTemplate db1SqlSessionTemplate(@Qualifier("db1SqlSessionFactory") SqlSessionFactory db1SqlSessionFactory) {
//        return new SqlSessionTemplate(db1SqlSessionFactory);
//    }
//}
